import javax.sound.midi.Sequence;

public class Producer_legacy implements Runnable {

	Thread thread;
	int currentNote, targetNote;
	Sequence sequence;
	boolean produce_more;
	MusicBuffer musicBuffer;
	GUI hell;
	Raga raga = new Raga("/media/Acad/FinalMajor/Oryx/src/shaymkalyan.xml");
	public Producer_legacy(MusicBuffer mb, GUI hl) {
		
		
		hell=hl;
		musicBuffer= mb;
		currentNote= 60;
		targetNote = 60;
		thread = new Thread(this, "PRODUCER_THREAD");
		System.out.println("New thread: " + thread);
		produce_more= false;

	}

	public void startThread() {
		thread.start();// Start the thread
		System.out.println("started thread: " + thread);

		produce_more = true;

	}

	
	
	// Dummy function to generate a series of notes.
	public int getNextNote() {
		targetNote= hell.getNoteValue();
		
		
		
		if (currentNote > targetNote) {
			currentNote = currentNote - 1;
		} else if (currentNote <= targetNote) {
			currentNote = currentNote + 1;
		}
		return currentNote;
	}

	
	@Override
	public synchronized void run() {
		
		int temp_note;
		int count=0;
		while(this.produce_more!=false)
		{
	
			if(musicBuffer.list.size()<1)
			{
			System.out.println("in run of producer");
			temp_note = getNextNote();
			musicBuffer.pushEvent(1, temp_note, 126, 0,100);
			count++;
			}
		} 
		
		musicBuffer.pushEvent(-1, 0, 0, 0,0);
		System.out.println("out of producer run");

	}

}
